package com.hzw.saas.service.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzw.saas.api.user.bo.CustomerBO;
import com.hzw.saas.service.user.model.Customer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 客户信息表 Mapper 接口
 * </p>
 *
 * @author zzl
 * @since 2021-04-03
 */
@Mapper
public interface CustomerMapper extends BaseMapper<Customer> {

    /**
     * 查询客户列表
     * @param page
     * @param fuzzyString
     * @param levelIds 等级
     * @param isOpen 是否开通
     * @return
     */
    IPage<Customer> queryCustomers(Page<?> page, @Param("fuzzyString") String fuzzyString, @Param("levelIds") List<String> levelIds, @Param("isOpen") Boolean isOpen ,@Param("channelTypes")List<String> channelTypes,
                                   @Param("userIds") List<String> userIds,@Param("channelIds")List<String> channelIds);

    /**
     * 获取未分配HPC账号的客户列表
     * @param page
     * @return
     */
    IPage<Customer> listUnBoundCustomerList(Page<?> page);

    /**
     * 获取客户已分配的HPC账号数量
     * @param userId
     * @return
     */
    int getAllotHpcCountByUserId(@Param("userId") String userId);


    /**
     * 获取试用合同客户列表（未绑定过HPC的客户列表）
     * @param page
     * @param fuzzy
     * @return
     */
    IPage<CustomerBO> listCustomerTrialList(Page<?> page, @Param("fuzzy") String fuzzy);

    @Select("<script>SELECT * FROM tb_customer LEFT JOIN tb_user_account on tb_customer.user_id = tb_user_account.user_id " +
        "ORDER BY tb_customer.create_time desc LIMIT #{count},#{size}</script>")
    List<Customer> efficientPageCustomers(@Param("count")Long count,@Param("size") Long size);
}
